package hflyeer.exceptions;

import hflyeer.base.BaseController;
import hflyeer.base.ResultInfo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * GlobalException
 *
 * @author hflyeer
 * @date 2021-06-03
 * @describe
 */
@ControllerAdvice
public class GlobalException extends BaseController {

    @ExceptionHandler(ParamsException.class)
    @ResponseBody
    public ResultInfo paramsException(ParamsException p){
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(p.getCode());
        resultInfo.setMsg(p.getMsg());
        return resultInfo;
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultInfo exception(Exception e){
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(500);
        resultInfo.setMsg("程序内部异常");
        resultInfo.setResult(e.getMessage());
        return resultInfo;
    }
}
